﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using MobySharp;
using MobySharp.Actions;
using MobySharp.Results;

namespace DemoApp
{
    public partial class ResultForm : Form
    {
        private string _tinyURL;

        public ResultForm(string tinyUrl)
        {
            InitializeComponent();
            _tinyURL = tinyUrl;
        }

        private void ResultForm_Load(object sender, EventArgs e)
        {
            var moby = new Mobypicture(Properties.Settings.Default.Key);
            var action = new GetMediaInfo(_tinyURL.Substring(_tinyURL.LastIndexOf("/") + 1));

            MediaInfoResult r = moby.GetMediaInfo(action);
            if (r.Result.Code == 0)
            {
                linkLabel1.Text = r.Post.LinkTiny;
                pictureBox1.ImageLocation = r.Post.Media.Square;
            }
            else
            {
                MessageBox.Show("Could not find Moby post");
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(linkLabel1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Process.Start(linkLabel1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(linkLabel1.Text);
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}